package com.ssy.lingxi.pay.service.assetAccount;

import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.pay.api.dto.request.assetAccount.*;
import com.ssy.lingxi.pay.api.dto.response.assetAccount.*;
import com.ssy.lingxi.pay.entity.assetAccount.MemberAssetAccount;
import com.ssy.lingxi.pay.model.assetAccount.MemberAssetAccountQuery;
import org.springframework.data.domain.Page;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 会员资金账户
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/7/21
 */
public interface IMemberAssetAccountService {
    /**
     * 查询会员资金账户
     * @param pageVO
     * @param memberAssetAccountMiddle
     * @return
     */
    Page<MemberAssetAccount> getMemberAssetAccountList(PageVO pageVO, MemberAssetAccountQuery memberAssetAccountMiddle);

    /**
     * 查询会员资金账户
     * @param id
     * @return Wrapper<MemberAssetAccount>
     */
    MemberAssetAccount getMemberAssetAccount(Long id);

    /**
     * 添加会员资金账户
     * @param memberAssetAccountList
     * @return
     */
    String saveOrUpdateMemberAssetAccount(List<MemberAssetAccount> memberAssetAccountList);

    /**
     * 修改会员资金账户
     * @param memberAssetAccountUpdateRequest
     * @return
     */
    String updateMemberAssetAccount(MemberAssetAccountUpdateRequest memberAssetAccountUpdateRequest);

    /**
     * 冻结/解冻会员资金账户
     * @param id
     * @param status
     */
    String updateMemberAssetAccountEnable(Long id, Integer status, String remark);

    /**
     * 资金账户充值
     * @param rechargeRequest
     * @return
     */
    AccountRechargeResponse rechargeAssetAccount(HttpServletRequest request, RechargeRequest rechargeRequest);

    /**
     * 资金账户充值(app)
     * @param rechargeRequest
     * @return
     */
    AccountRechargeAppResponse rechargeAssetAccountApp(HttpServletRequest request, RechargeRequest rechargeRequest);

    /**
     * 资金账户充值(小程序)
     * @param rechargeAppletRequest
     * @return
     */
    AccountRechargeAppletResponse rechargeAssetAccountApplet(HttpServletRequest request, RechargeAppletRequest rechargeAppletRequest);

    /**
     * 资金账户充值(H5)
     *
     * @param request
     * @param rechargeJsApiRequest
     * @return
     */
    AccountRechargeJsApiResponse rechargeAssetAccountJsApi(HttpServletRequest request, RechargeJsApiRequest rechargeJsApiRequest);

    /**
     * 查询账户充值结果
     * @param tradeRecordId
     * @return
     */
    Boolean getRechargeResult(Long tradeRecordId);

    /**
     * 支付回调
     * @param out_trade_no 交易单号
     * @param trade_no 支付平台订单号
     */
    void payNotify(String out_trade_no, String trade_no);

    /**
     * 更新交易记录为支付失败
     * @param accountTradeRecordId 交易记录id
     */
    void updateAccountTradeRecordPayingFail(Long accountTradeRecordId);

    /**
     * 资金账户提现
     * @param cashOutRequest
     * @return
     */
    String cashOutAssetAccount(CashOutRequest cashOutRequest);

    /**
     * 支付提现
     * @param payRequest
     */
    String payCashOut(PayRequest payRequest);

    /**
     * 余额支付
     * @param balancePayRequest
     * @return
     */
    String balancePay(BalancePayRequest balancePayRequest);

    /**
     * 余额返现
     * @param balanceCashbackRequest
     * @return
     */
    String balanceCashback(BalanceCashbackRequest balanceCashbackRequest);

    /**
     * 余额退款
     * @param balanceRefundRequest
     * @return
     */
    Boolean balanceRefund(BalanceRefundRequest balanceRefundRequest);

    /**
     * 统一检验账户
     * @return
     */
    void checkMemberAssetAccount(MemberAssetAccount memberAssetAccount);

    /**
     * 查询登录用户的账户余额
     * @param fundMode 资金归集模式: 1-平台; 2-会员直接到账
     * @param parentMemberId 上级会员id
     * @param parentMemberRoleId 上级会员角色id
     */
    Double getUserBalance(Integer fundMode, Long memberId, Long memberRoleId, Long parentMemberId, Long parentMemberRoleId);

    /**
     * 查询采购商的账户余额
     * @param childMemberId 下级会员id
     * @param childMemberRoleId 下级会员角色id
     */
    Double getChildUserBalance(Long memberId, Long memberRoleId, Long childMemberId, Long childMemberRoleId);

    /**
     * 查询登录用户的所有账户余额
     * @param memberId
     * @param memberRoleId
     * @return
     */
    Double getUserAllBalance(Long memberId, Long memberRoleId);

    /**
     * 查询平台账户详情
     */
    MemberAssetAccount getPlatFormAssetAccount(UserLoginCacheDTO sysUser);

    /**
     * 查询会员用户的账户详情
     * @param memberId              登录用户会员id
     * @param memberRoleId          登录用户会员角色id
     * @param parentMemberId        上级会员id
     * @param parentMemberRoleId    上级会员角色id
     * @return  账户详情
     */
    MemberAssetAccountResponse getUserAssetAccount(Long memberId, Long memberRoleId, Long parentMemberId, Long parentMemberRoleId);

}
